package com.cn.demo.service;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.cn.demo.entity.SeckillOrder;
import com.cn.demo.mapper.OrderMapper;
import org.springframework.stereotype.Service;

/**
 * 描述
 *
 * @author wangjf
 * @version 1.0
 * @createDate 2019/11/18 14:10
 * @projectName test
 */
@Service
public class OrderService extends BaseService<OrderMapper, SeckillOrder> {


    /**
     * 未支付订单取消
     *
     * @param orderNo
     * @return java.lang.Boolean
     * @author: wangjf
     * @createTime: 2019/11/20 11:31
     */
    public Boolean cancelOrder(String userIdQueueId, String orderNo) {

        String[] userIdQueueIds = userIdQueueId.split("_");

        SeckillOrder one = getOne(Wrappers.<SeckillOrder>query().lambda().eq(SeckillOrder::getOrderNo, orderNo).eq(SeckillOrder::getUserId, userIdQueueIds[1]).eq(SeckillOrder::getQueueId, userIdQueueIds[0]));
        if (one == null) {
            return Boolean.FALSE;
        }

        if (one.getStatus() == 0) {
            SeckillOrder seckillOrder = new SeckillOrder();
            seckillOrder.setStatus(2);
            seckillOrder.setId(one.getId());
            return updateById(seckillOrder) == 1 ? Boolean.TRUE : Boolean.FALSE;
        }
        return Boolean.TRUE;

    }

}
